package com.example.hzq.food.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hzq.food.R;
import com.example.hzq.food.activity.Shop;
import com.example.hzq.food.bean.ShopBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by hzq on 2017/6/10.
 */

public class Shopadapter extends RecyclerView.Adapter{
    private List<ShopBean> list;
    private Context context;
    private LayoutInflater layoutInflater;
    public static int shop_id;
    public  static String shopname,shoppn,shopaddress,shopintro,imagepath;
    public Shopadapter(Context context){
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }
    public void setList(List<ShopBean>list){
        this.list=list;
        notifyDataSetChanged();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        private TextView tv_title,tv_descript,tv_phone;
        public ViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.imageView);
            tv_title = (TextView) itemView.findViewById(R.id.textView18);
            tv_descript = (TextView) itemView.findViewById(R.id.textView19);
            tv_phone = (TextView) itemView.findViewById(R.id.textView20);
        }
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=layoutInflater.inflate(R.layout.item,parent,false);
        return new Shopadapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder,final int position) {
        final ShopBean shopBean=list.get(position);
        if (shopBean == null)
            return;
        ViewHolder viewHolder=(ViewHolder)holder;
        Picasso.with(context).load(shopBean.getPic()).placeholder(R.drawable.ic_default_adimage).into(viewHolder.imageView);
        viewHolder.tv_title.setText(shopBean.getShopname());
        viewHolder.tv_descript.setText(shopBean.getIntro());
        viewHolder.tv_phone.setText(shopBean.getPhonenum());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             shop_id=shopBean.getShop_id();
                shopname=shopBean.getShopname();
                shoppn=shopBean.getPhonenum();
                shopaddress=shopBean.getAddress();
                shopintro=shopBean.getIntro();
                imagepath=shopBean.getPic();
                Intent intent=new Intent();
                intent.setClass(context,Shop.class);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if(list==null) return  0;
        else
            return list.size();
    }
}
